<!-- 报警成功页面 -->
<template>
	<view class="bg-white" style="height: 100vh;">
		<cu-custom bgColor="bg-white">
			<block style="color: ##777777;font-size: 32rpx;" slot="content">火情预警</block>
		</cu-custom>
		<view style="height: 90vh;display: flex;flex-direction: column;place-items: center;">
			<image src="" style="margin: 40px 0"></image>
			<view class="my-text" style="font-size: 18px;font-weight: bold;line-height: 30px;margin: 0 25px;height: 118px;padding: 15px;">{{msg}}</view>
			<view style="position: fixed;bottom: 70px;width: 100%;text-align: center;" class="margin-top">
			<!-- v-if="endShow" -->
				<button v-if="endShow" class="cu-btn my-btn shadow" style="background: #fff !important; color: rgba(255, 143, 31, 1);border: 1px solid rgba(255, 143, 31, 1);" @click="jshq">结束火情</button>
				<button class="my-btn cu-btn bg-blue" style="margin-left: 20px;" @click="back">返回首页</button>
			</view>
		</view>

		<view class="cu-modal" :class="model">
			<view class="cu-dialog">
				<view class="tip">提示</view>
				<view class="padding-xl">
					如火情未扑灭，恶意结束火情信息将承担相应法律责任
				</view>
				<view class="cu-bar foot-btn">
					<button type="info" class="text-blue" @click="hqcancle">取消</button>
					<button class="text-green" @click="tjjshq">确定</button>
				</view>
			</view>
		</view>
		<message />
	</view>
</template>

<script>
	import * as constants from '@/common/config.js';
	export default {
		onShow() {

		},
		data() {
			return {
				title: '',
				msg: '',
				ucId: '',
				fireInfoId: '',
				audioId: '',
				bgAudioManager: {},
				model: '',
				imgUrl: '',
				isEnd: false
			}
		},
		onLoad(option) {
			this.ucId = option.noticeId
			this.fireInfoId = option.fireInfoId
			this.audioId = option.audioId
			this.hasEndAccess()
			this.xq()
		},
		computed:{
			endShow(){
				let roleCode = uni.getStorageSync('roleCode');
				return this.isEnd||roleCode=="XFZD-ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"||roleCode=="XZ-ADMIN"
			}
		},
		methods: {
			hasEndAccess() {
				let that = this
				// 封装参数
				let vparams = {
					"ucId": that.fireInfoId,
				}
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: '/wx/fireInfo/hasEndAccess',
					data: vparams
				}).then(function(res) {
					if (res.data.code == 0) {
						that.isEnd = res.data.data
					}
				}).catch(function(e) {
				  uni.showToast({
					title: '操作失败',
					icon: 'error'
				  })
				})
			},
			hqcancle() {
				this.model = ''
			},
			playAudio(path) {
				let app = getApp()
				app.globalData.socketObj.playAudio(path)
			},
			stopAudio() {
				let app = getApp()
				app.globalData.socketObj.stopAudio()
			},
			back() {
				uni.navigateTo({
					url: '../../pages/index/index'
				})
			},
			xq() {
				let params = {
					"ucId": this.ucId
				}
				let that = this
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: '/wx/notice/getInNoticeVo',
					data: params
				}).then(function(res) {
					that.msg = res.data.data.noticeContent
					that.title = res.data.data.noticeName

					// 音频
					let path = ''
					if (that.audioId == 0) {

					} else if (that.audioId == 1) {
						path = "https://www.cetczhxf.com/mp3/first.mp3"
					} else if (that.audioId == 2) {
						path = "https://www.cetczhxf.com/mp3/second.mp3"
					} else if (that.audioId == 3) {
						path = "https://www.cetczhxf.com/mp3/third.mp3"
					} else if (that.audioId == 4) {
						path = "https://www.cetczhxf.com/mp3/fourth.mp3"
					} else if (that.audioId == 5) {
						path = "https://www.cetczhxf.com/mp3/fifth.mp3"
					} else if (that.audioId == 6) {
						path = "https://www.cetczhxf.com/mp3/sixth.mp3"
					} else if (that.audioId == 7) {
						path = "https://www.cetczhxf.com/mp3/seventh.mp3"
					} else if (that.audioId == 8) {
						path = "https://www.cetczhxf.com/mp3/eighth.mp3"
					}
					that.playAudio(path)
				}).catch(function(e) {

				})
			},
			jshq() {
				this.model = 'show'
			},
			up() {
				let that = this
				// 封装参数
				let vparams = {
					"ucId": this.fireInfoId,
					"confirmFireFile": this.imgUrl
				}
				// 请求数据
				let app = getApp()
				app.globalData.request({
					url: 'wx/firemanage/generateFireFinishPutFire',
					data: vparams
				}).then(function(res) {
					if (res.data.code == 0) {
						that.stopAudio()
						// uni.navigateTo({
						// 	url: '../../pages/index/index'
						// })
					}
				}).catch(function(e) {
					uni.showToast({
						title: '操作失败',
						icon: 'error'
					})
				})
			},
			uploadFile(path) {
				let that = this
				let app = getApp()
				let token = app.globalData.getToken('authorization')
				const uploadTask = uni.uploadFile({
					url: constants.API + 'wx/common/upload',
					filePath: path,
					header: {
						"authorization": token
					},
					name: 'file',
					success(uploadFileRes)  {
						let obj = JSON.parse(uploadFileRes.data)
						that.imgUrl = obj.data;
						that.up()
					}
				})
			},
			tjjshq() {
				// 首先拍照片
				let that = this
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera'], //从相册选择
					success: (res) => {
						let path = res.tempFilePaths
						// 上传
						this.uploadFile(path[0]);
					}
				})
			},
		}
	}
</script>

<style>
	.my-text{
		background: url('') no-repeat;
		background-size: 100% 100%;
	}
	.bg-yellow{
		background-image: linear-gradient(90deg, #FAB53A 4%, #EFA21A 99%);
		box-shadow: 0 0 12px 0 rgba(250, 181, 58, 0.50);
	}
	.my-btn {
		height: 70rpx;
		border-radius: 5px;
		ont-family: PingFangSC-Medium;
		color: #FFFFFF;
		letter-spacing: 0;
		text-align: center;
		width: 150px;
	}
	.foot-btn {
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
</style>
